<%--
  Created by IntelliJ IDEA.
  User: FENG1
  Date: 2022/5/12
  Time: 11:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>Title</title>
    <link rel="stylesheet" href="static/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">仓库名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="reponseTypeName" lay-verify="title" autocomplete="off" placeholder="请输入仓库名称"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">仓库负责人</label>
                    <div class="layui-input-block">
                        <select name="eid">
                            <option value="">请选择一个负责人</option>
                            <c:forEach items="${emps}" var="e">
                                <option value="${e.eId}">${e.eName}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">仓库容量</label>
                    <div class="layui-input-block">
                        <input class="layui-input" lay-verify="number" type="text" name="capcity" id="goodmount">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <input type="text" name="remark" lay-verify="title" autocomplete="off" placeholder="请输入仓库备注"
                               class="layui-input">
                    </div>
                </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="static/component/layui/layui.js"></script>
<script src="static/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery'], function() {
        let form = layui.form;
        let $ = layui.jquery;
        $("#goodmount").focus(function(){
            /*if($(this).val()<=0){
                $(this).val(100);
            }*/
        }).blur(function () {
            if($(this).val()<=0){
                $(this).val(100);
            }
        })
        form.on('submit(user-save)', function(data) {
            let depName = $("[name='reponseTypeName']").val();
            let eid = $("[name='eid']").val();
            if(depName==""||depName==null){
                layer.msg("仓库名称不能为空！");
                return false;
            }

            if(eid==""||eid==null){
                layer.msg("仓库负责人不能为空！");
                return false;
            }
            $.ajax({
                url: 'repostory/addRep',
                data: data.field,
                type: 'post',
                success: function(result) {
                    if (result.success) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            //window.location.reload();s
                            parent.parent.$(".layui-icon-refresh-1").click();
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>